<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/qt3support/tools/q3ptrcollection.cpp -->
<head>
  <title>Qt 4.3: Q3PtrCollection Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">Q3PtrCollection Class Reference<br /><sup><sup>[<a href="qt3support.html">Qt3Support</a> module]</sup></sup></h1>
<p>The Q3PtrCollection class is the base class of most pointer-based Qt collections. <a href="#details">More...</a></p>
<pre> #include &lt;Q3PtrCollection&gt;</pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See <a href="porting4.html">Porting to Qt 4</a> for more information.</p>
<p>Inherited by <a href="q3asciicache.html">Q3AsciiCache</a>, <a href="q3asciidict.html">Q3AsciiDict</a>, <a href="q3cache.html">Q3Cache</a>, <a href="q3dict.html">Q3Dict</a>, <a href="q3intcache.html">Q3IntCache</a>, <a href="q3intdict.html">Q3IntDict</a>, <a href="q3ptrdict.html">Q3PtrDict</a>, <a href="q3ptrlist.html">Q3PtrList</a>, <a href="q3ptrqueue.html">Q3PtrQueue</a>, <a href="q3ptrstack.html">Q3PtrStack</a>, and <a href="q3ptrvector.html">Q3PtrVector</a>.</p>
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="q3ptrcollection-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-types"></a>
<h3>Public Types</h3>
<ul>
<li><div class="fn"/>typedef <b><a href="q3ptrcollection.html#Item-typedef">Item</a></b></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/>bool <b><a href="q3ptrcollection.html#autoDelete">autoDelete</a></b> () const</li>
<li><div class="fn"/>virtual void <b><a href="q3ptrcollection.html#clear">clear</a></b> () = 0</li>
<li><div class="fn"/>virtual uint <b><a href="q3ptrcollection.html#count">count</a></b> () const = 0</li>
<li><div class="fn"/>void <b><a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a></b> ( bool <i>enable</i> )</li>
</ul>
<a name="protected-functions"></a>
<h3>Protected Functions</h3>
<ul>
<li><div class="fn"/><b><a href="q3ptrcollection.html#Q3PtrCollection">Q3PtrCollection</a></b> ()</li>
<li><div class="fn"/><b><a href="q3ptrcollection.html#Q3PtrCollection-2">Q3PtrCollection</a></b> ( const Q3PtrCollection &amp; <i>source</i> )</li>
<li><div class="fn"/>virtual <b><a href="q3ptrcollection.html#dtor.Q3PtrCollection">~Q3PtrCollection</a></b> ()</li>
<li><div class="fn"/>virtual void <b><a href="q3ptrcollection.html#deleteItem">deleteItem</a></b> ( Item <i>d</i> ) = 0</li>
<li><div class="fn"/>virtual Item <b><a href="q3ptrcollection.html#newItem">newItem</a></b> ( Item <i>d</i> )</li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The Q3PtrCollection class is the base class of most pointer-based Qt collections.</p>
<p>The Q3PtrCollection class is an abstract base class for the Qt collection classes QDict, <a href="q3ptrlist.html">Q3PtrList</a>, etc.</p>
<p>A Q3PtrCollection only knows about the number of objects in the collection and the deletion strategy (see <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>()).</p>
<p>A collection is implemented using the <tt>Item</tt> (generic collection item) type, which is a <tt>void*</tt>. The template classes that create the real collections cast the <tt>Item</tt> to the required type.</p>
<hr />
<h2>Member Type Documentation</h2>
<h3 class="fn"><a name="Item-typedef"></a>typedef Q3PtrCollection::Item</h3>
<p>This type is the generic &quot;item&quot; in a <a href="q3ptrcollection.html">Q3PtrCollection</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="Q3PtrCollection"></a>Q3PtrCollection::Q3PtrCollection ()&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Constructs a collection. The constructor is protected because <a href="q3ptrcollection.html">Q3PtrCollection</a> is an abstract class.</p>
<h3 class="fn"><a name="Q3PtrCollection-2"></a>Q3PtrCollection::Q3PtrCollection ( const Q3PtrCollection &amp; <i>source</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Constructs a copy of <i>source</i> with <a href="q3ptrcollection.html#autoDelete">autoDelete</a>() set to false. The constructor is protected because <a href="q3ptrcollection.html">Q3PtrCollection</a> is an abstract class.</p>
<p>Note that if <i>source</i> has autoDelete turned on, copying it will risk memory leaks, reading freed memory, or both.</p>
<h3 class="fn"><a name="dtor.Q3PtrCollection"></a>Q3PtrCollection::~Q3PtrCollection ()&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Destroys the collection. The destructor is protected because <a href="q3ptrcollection.html">Q3PtrCollection</a> is an abstract class.</p>
<h3 class="fn"><a name="autoDelete"></a>bool Q3PtrCollection::autoDelete () const</h3>
<p>Returns the setting of the auto-delete option. The default is false.</p>
<p>See also <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
<h3 class="fn"><a name="clear"></a>void Q3PtrCollection::clear ()&nbsp;&nbsp;<tt> [pure virtual]</tt></h3>
<p>Removes all objects from the collection. The objects will be deleted if auto-delete has been enabled.</p>
<p>See also <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
<h3 class="fn"><a name="count"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3PtrCollection::count () const&nbsp;&nbsp;<tt> [pure virtual]</tt></h3>
<p>Returns the number of objects in the collection.</p>
<h3 class="fn"><a name="deleteItem"></a>void Q3PtrCollection::deleteItem ( <a href="q3ptrcollection.html#Item-typedef">Item</a> <i>d</i> )&nbsp;&nbsp;<tt> [pure virtual protected]</tt></h3>
<p>Reimplement this function if you want to be able to delete items.</p>
<p>Deletes an item that is about to be removed from the collection.</p>
<p>This function has to reimplemented in the collection template classes, and should <i>only</i> delete item <i>d</i> if auto-delete has been enabled.</p>
<p><b>Warning:</b> If you reimplement this function you must also reimplement the destructor and call the virtual function <a href="q3ptrcollection.html#clear">clear</a>() from your destructor. This is due to the way virtual functions and destructors work in C++: Virtual functions in derived classes cannot be called from a destructor. If you do not do this, your deleteItem() function will not be called when the container is destroyed.</p>
<p>See also <a href="q3ptrcollection.html#newItem">newItem</a>() and <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
<h3 class="fn"><a name="newItem"></a><a href="q3ptrcollection.html#Item-typedef">Item</a> Q3PtrCollection::newItem ( <a href="q3ptrcollection.html#Item-typedef">Item</a> <i>d</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Virtual function that creates a copy of an object that is about to be inserted into the collection.</p>
<p>The default implementation returns the <i>d</i> pointer, i.e&#x2e; no copy is made.</p>
<p>This function is seldom reimplemented in the collection template classes. It is not common practice to make a copy of something that is being inserted.</p>
<p>See also <a href="q3ptrcollection.html#deleteItem">deleteItem</a>().</p>
<h3 class="fn"><a name="setAutoDelete"></a>void Q3PtrCollection::setAutoDelete ( bool <i>enable</i> )</h3>
<p>Sets the collection to auto-delete its contents if <i>enable</i> is true and to never delete them if <i>enable</i> is false.</p>
<p>If auto-deleting is turned on, all the items in a collection are deleted when the collection itself is deleted. This is convenient if the collection has the only pointer to the items.</p>
<p>The default setting is false, for safety. If you turn it on, be careful about copying the collection - you might find yourself with two collections deleting the same items.</p>
<p>Note that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has a remove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item.</p>
<p>See also <a href="q3ptrcollection.html#autoDelete">autoDelete</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
